// app/model/contract_template.js
module.exports = app => {
  const { TEXT, VIRTUAL } = app.Sequelize;

  return app.model.define('contract_template', {
    content: {
      type: TEXT,
      comment: '加密存储的模板内容',
      set(val) {
        this.setDataValue('content', app.service.zcyCrypto.encryptSM4(val));
      },
      get() {
        return app.service.zcyCrypto.decryptSM4(this.getDataValue('content'));
      }
    },
    version_hash: {
      type: STRING(64),
      comment: '模板版本哈希值'
    }
  }, {
    hooks: {
      beforeUpdate: template => {
        template.version_hash = app.service.zcyCrypto.hashSM3(template.content);
      }
    }
  });
};